<template>
    <view-box style="background:#F3F6F7;">
      <div style="height:10px;"></div>
      <div class="border-addres">
        <x-input title="学校名称:" v-model="addBasic.school_name" name="school_name" placeholder="请输入学校名称" ></x-input>
        <div style="height:1px;width:92%;margin-left:4%;background:#f4f4f4"></div>
        <popup-picker title="学历:" :data="value6" v-model="addBasic.major" value-text-align="right"></popup-picker>
        <div style="height:1px;width:92%;margin-left:4%;background:#f4f4f4"></div>
        <x-input title="专业名称:" name="education" v-model="addBasic.education" placeholder="请输入专业名称" ></x-input>
      </div>
      <div style="height:10px;"></div>
      <div class="border-addres">
         <div class="btn-set-default"><check-icon :value.sync="addBasic.is_unified" >统招</check-icon></div>
      </div>
      <div style="height:10px;"></div>
      <div class="border-addres">
        <datetime v-model="addBasic.start_time"  :min-year=1980 :max-year=2050 format="YYYY-MM" @on-change="change" title="入学时间:"></datetime>
        <div style="height:1px;width:92%;margin-left:4%;background:#f4f4f4"></div>
        <datetime v-model="addBasic.over_time"   :min-year=1980 :max-year=2050 format="YYYY-MM" @on-change="change" title="离校时间:"></datetime>
      </div>
        <group style="width:92%;margin-left:4%;">
            <x-button style="background:#32B6C6;color:#fff;" @click.native="saveup()">确定</x-button>
        </group>
    </view-box>
</template>
<script>
import { ViewBox, Box, XInput, Group, XButton, Datetime, PopupPicker, CheckIcon } from 'vux'
export default {
  name: 'Addresume',
  components: {
    ViewBox,
    Box,
    XInput,
    Group,
    XButton,
    Datetime,
    PopupPicker,
    CheckIcon
  },
  data () {
    return {
      radio001: ['是否统招'],
      value4: '',
      value3: '',
      value6: [['博士后', '博士', 'MBA/EMBA', '硕士', '本科', '大专', '中专', '中技', '高中', '初中']],
      is_unified: false,
      pid: '',
      tabldata: {
        id: '',
        school_name: '',
        major: '',
        education: '',
        is_unified: '',
        start_time: '',
        over_time: ''
      },
      addBasic: {
        school_name: '',
        education: '',
        start_time: '',
        over_time: ''
      },
      addiss: {},
      data: [],
      addpid: '',
      addResume: {}
    }
  },
  computed: {
    disabled () {
      console.log('zunhh')
    },
    userInfo () {
      return this.$store.getters.userInfo
    }
  },
  mounted () {
    this._getconm()
    this._getresume()
    if (!this.$store.state.auth.userInfo) {
      this.$store.dispatch('getUserInfo')
    }
  },
  methods: {
    change () {
      console.log('zhou')
    },
    _getresume () {
      this.$http.get('/resume').then(response => {
        if (this.$route.query.id !== undefined) {
          response.data.education.forEach((item) => {
            if (parseInt(item.id) === parseInt(this.$route.query.id)) {
              let obj = {
                uid: item.uid,
                school_name: item.school_name,
                major: [item.major],
                education: item.education,
                is_unified: Boolean(item.is_unified),
                start_time: item.start_time,
                over_time: item.over_time
              }
              this.data.push(obj)
              this.addBasic = this.data[0]
            }
          })
        }
        this.addpid = response.data.id
        // console.log(this.addressValue)
      }).catch(error => {
        console.log(error)
      })
    },
    saveup () {
      if (this.$route.query.id !== undefined) {
        this.updata()
      } else {
        this.save()
      }
    },
    save () {
      var isunified = ''
      if (this.addBasic.is_unified === true) {
        isunified = 1
      } else {
        isunified = 0
      }
      if (this.addBasic.school_name === '' || this.addBasic.job_title === '') {
        this.$vux.toast.show({
          text: '不能为空',
          type: 'text'
        })
        return false
      }
      let data = {
        uid: this.userInfo.id ? this.userInfo.id : 0,
        pid: this.addpid,
        school_name: this.addBasic.school_name,
        major: String(this.addBasic.major),
        job_title: this.addBasic.job_title,
        education: this.addBasic.education,
        is_unified: isunified,
        start_time: this.addBasic.start_time,
        over_time: this.addBasic.over_time
      }
      this.$http.post('/resume/storeEducation', data).then(response => {
        this.$vux.toast.show({
          text: response.data.message,
          type: 'text'
        })
        this.$router.push({ path: '/myresume' })
        console.log(response)
      }).catch(error => {
        console.log(error)
      })
    },
    updata () {
      var isunified = ''
      if (this.addBasic.is_unified === true) {
        isunified = 1
      } else {
        isunified = 0
      }
      let data = {
        id: this.$route.query.id,
        school_name: this.addBasic.school_name,
        major: String(this.addBasic.major),
        job_title: this.addBasic.job_title,
        education: this.addBasic.education,
        is_unified: isunified,
        start_time: this.addBasic.start_time,
        over_time: this.addBasic.over_time
      }
      this.$http.put('/resume/updateEducation', data).then(response => {
        this.$vux.toast.show({
          text: response.data.message,
          type: 'text'
        })
        this.$router.push({ path: '/myresume' })
        console.log(response)
      }).catch(error => {
        console.log(error)
      })
    },
    _getconm () {
      this.$http.post('/entrance').then(response => {
        this.pid = response.data.data.id
      })
    }
  }
}
</script>

<style scoped>
    .btn-set-default {
        flex: 1;
        line-height: 50px;
    }
    .border-addres{
      width: 92%;
      margin-left: 4%;
      background: #fff;
      border-radius: 7px;
    }
</style>
<style>
 .weui-cells:before{
        border-top: 0px solid #D9D9D9 !important;
    }
    .weui-cells:after{
        border-bottom: 0px solid #D9D9D9 !important;
    }
 .border-addres .vux-cell-box:not(:first-child):before {
    border-top: 0px solid #D9D9D9!important;
}
.vux-check-icon > .weui-icon-success:before, .vux-check-icon > .weui-icon-success-circle:before {
    color: #32B6C6!important;
}
.border-addres .weui-label {
    display: block;
    width: 105px;
    word-wrap: break-word;
    word-break: break-all;
    color: #bababa;
}
.weui-cell:before {
    border-top: 0px solid #D9D9D9!important;
}
.border-addres .vux-datetime {
    color: #bababa!important;
}
</style>